package encaps.action;

import encaps.entities.Comment;
import encaps.entities.Grant;
import encaps.entities.MovieLocal;
import encaps.entities.MoviePersonInfo;
import encaps.resources.Labels;
import encaps.utils.SystemException;
import encaps.utils.XMLHelper;
import java.util.*;
import javax.ejb.*;
import org.jdom.Element;

public class ShowEmptyMoviePageAction extends Action {

    public static final String SHOW_EMPTY_MOVIE_PAGE = "showEmptyMoviePage";
    protected ActionContext actionContext;

    public ShowEmptyMoviePageAction(ActionContext context, Grant requiredGrant) {
        actionContext = context;
        this.requiredGrant = requiredGrant;
    }

    @Override
    public Element execute() throws ActionExecutionException {
        try {
            String username = actionContext.getUserLogin();
            return XMLHelper.toXMLElement(new DefaultMovieFields(0L),
                    Labels.getLabel(Labels.CREATE_MOVIE), true, username,
                    actionContext.getUserRole(), new HashMap<String, String>());
        } catch (SystemException ex) {
            throw new ActionExecutionException(Labels.getLabel(Labels.CANNOT_EXECUTE_ACTION), ex);
        }
    }

    protected static class DefaultMovieFields implements MovieLocal {

        private Long id = Long.valueOf(0);
        private String title = "";
        private String pic = "";
        private Set genres = null;
        private String producingCountries = "";
        private Date russianReleaseDate = new Date(0L);
        private Date worldReleaseDate = new Date(0L);
        private String studio = "";
        private Integer budget = Integer.valueOf(0);
        private Integer worldCash = Integer.valueOf(0);
        private Integer length = Integer.valueOf(0);
        private String description = "";
        //private Double rating = Double.valueOf(0D);
        private HashSet<MoviePersonInfo> persons = new HashSet<MoviePersonInfo>();

        public DefaultMovieFields(Long id) {
            this.id = id;
        }

        public Long getId() {
            return id;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getPicture() {
            return pic;
        }

        public void setPicture(String pic) {
            this.pic = pic;
        }

        public String getGenres() {
            if (genres == null) {
                return "";
            } else {
                String g = genres.toString();
                return g.substring(1, g.length() - 1);
            }
            //return genres;
        }

        public void setGenres(HashSet genres) {
            this.genres = genres;
        }

        public String getCountries() {
            return producingCountries;
        }

        public void setCountries(String producingCountries) {
            this.producingCountries = producingCountries;
        }

        public Date getRussianReleaseDate() {
            return russianReleaseDate;
        }

        public void setRussianReleaseDate(Date russianReleaseDate) {
            this.russianReleaseDate = russianReleaseDate;
        }

        public Date getWorldReleaseDate() {
            return worldReleaseDate;
        }

        public void setWorldReleaseDate(Date worldReleaseDate) {
            this.worldReleaseDate = worldReleaseDate;
        }

        public String getStudio() {
            return studio;
        }

        public void setStudio(String studio) {
            this.studio = studio;
        }

        public Integer getBudget() {
            return budget;
        }

        public void setBudget(Integer russianCash) {
            this.budget = russianCash;
        }

        public Integer getWorldCash() {
            return worldCash;
        }

        public void setWorldCash(Integer worldCash) {
            this.worldCash = worldCash;
        }

        public Integer getLength() {
            return length;
        }

        public void setLength(Integer length) {
            this.length = length;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public Double getRating() {
            //return rating;
            return Double.valueOf(0);
        }

        public void addRating(Double rating, Long user_id, Date date) throws CreateException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public HashSet<MoviePersonInfo> getPersons() {
            return persons;
        }

        public void setPersons(HashSet<MoviePersonInfo> persons) {
            this.persons = persons;
        }

        public Integer getNvotes() {
            return 0;
        }

        public String stringRepresentation() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Long addComment(Long user_id, String content, Date date) throws CreateException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void removeComment(Long comment_id) throws RemoveException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void updateComment(Long comment_id, String content, Date date) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public LinkedList<Comment> getComments() {
            //return new LinkedList
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public EJBLocalHome getEJBLocalHome() throws EJBException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Object getPrimaryKey() throws EJBException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void remove() throws RemoveException, EJBException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public boolean isIdentical(EJBLocalObject obj) throws EJBException {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
}
